package com.example.redis;

import org.junit.Before;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

public class JedisTester {
    private Jedis jedis;
    @Before
    public void setup() {
        //连接redis服务器，127.0.0.1:6379
        jedis = new Jedis("127.0.0.1",6379);
        //授权认证
        //jedis.auth("foobared");
    }

    @Test
    public void testString(){
        setup();
        //添加数据
        //向key-->name中放入value-->ktjiaoyu
        jedis.set("name","ktjiaoyu");
        //执行结果：ktjiaoyu
        System.out.println(jedis.get("name"));
        //删除某个键
        jedis.del("name");
        System.out.println(jedis.get("name"));
        //设置多个键值对
        jedis.mset("name","ktjiaoyu","age","17","add","cz");
        //进行加1操作
        jedis.incr("age");
        System.out.println(jedis.get("name") + "-" + jedis.get("age") + "-" + jedis.get("add"));
    }
}
